# CHES Global Dataset Analysis

This repository contains scripts for reproducing the paper titled *"A Global Scale of Economic Left-Right Party Positions: Cross-National and Cross-Expert Perceptions of Party Placements"*. The scripts are organized to handle data preparation, model estimation, and result visualization.

## Scripts Overview

### `scripts/00_data.R`
This script merges data from various CHES surveys (Europe, Latin America, US, Australia, Israel, Canada) into a single global dataset. It performs the following tasks:
- Loads and processes data from different regions.
- Standardizes variable names and formats.
- Appends datasets into a unified structure.
- Handles missing data and checks for vignette equivalence.
- Reshapes the data into wide format for analysis.
- Saves the processed data in both long and wide formats.

### `scripts/01_BAM_models.R`
This script estimates Bayesian Aldrich-McKelvey (BAM) models using the prepared CHES data. It includes:
- Data preparation for BAM models.
- Estimation of BAM models using Stan.
- Estimation of HBAM (Hierarchical BAM) models with and without multi-group structures.
- Saves the model outputs for further analysis.

### `scripts/02_figures.R`
This script generates all figures for the analysis and manuscript. It includes:
- Visualization of vignette placements by region and country.
- Posterior distributions of alpha and beta parameters.
- Comparisons of BAM estimates with CHES data.
- Linear models predicting alpha and beta parameters based on expert characteristics.
- Additional figures for supplementary materials.

### `scripts/03_correlations_sm.R`
This script compares the main parameters of interest from the BAM and HBAM models. It includes:
- Extraction of party positions and expert-level parameters.
- Correlation analysis between BAM, HBAM, and CHES estimates.
- Preparation of tables for supplementary materials.

## Outputs
- Processed datasets (`outputs/df_global_expert_party.rds`, `outputs/df_global_expert.rds`).
- BAM and HBAM model outputs (`outputs/bam.rds`, `outputs/hbam_base.rds`, `outputs/hbam_multi.rds`).
- Figures for the manuscript and supplementary materials (`figures/`).
- Session information for reproducibility (`outputs/session_info/`).

## Requirements
The scripts require the following R packages:
- `tidyverse`
- `haven`
- `rstan`
- `hbamr`
- `ggpubr`
- `pacman` (for package management)

## Usage
1. Run `00_data.R` to prepare the datasets.
2. Run `01_BAM_models.R` to estimate the BAM and HBAM models.
3. Use `02_figures.R` to generate visualizations for the analysis.
4. Use `03_correlations_sm.R` to perform correlation analysis and prepare supplementary tables.

## Reproducibility
Session information is saved for each script to ensure reproducibility. Refer to the `outputs/session_info/` directory for details.

## Questions
For questions or further information, please contact:

Nicolás de la Cerda  

ndelacerdacoya@tulane.edu  

[https://www.nicolasdelacerda.com](https://www.nicolasdelacerda.com)